public class FindFirstCommonNode {
    // 两个链表的第一个公共节点
    // https://www.nowcoder.com/practice/6ab1d9a29e88450685099d45c9e31e46?tpId=295&tags=&title=&difficulty=0&judgeStatus=0&rp=0&sourceUrl=%2Fexam%2Foj%3FquestionJobId%3D10%26subTabName%3Donline_coding_page
    public ListNode FindFirstCommonNode(ListNode pHead1, ListNode pHead2) {
        int count1 = 0;
        ListNode cur1 = pHead1;
        while (cur1 != null) {
            cur1 = cur1.next;
            count1++;
        }
        ListNode cur2 = pHead2;
        int counr2 = 0;
        while (cur2 != null) {
            cur2 = cur2.next;
            counr2++;
        }
        if (count1 < counr2) {
            ListNode tmp = pHead1;
            pHead1 = pHead2;
            pHead2 = tmp;
        }
        cur1 = pHead1;
        cur2 = pHead2;
        for (int i = 0; i < Math.abs(count1-counr2); i++) {
            cur1 = cur1.next;
        }
        while (cur1 != null && cur2 != null) {
            if (cur1 == cur2) {
                return cur1;
            }
            cur1 = cur1.next;
            cur2 = cur2.next;
        }
        return null;
    }
}
